package nbp.currency.gui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import nbp.currency.logic.CurrencyWrapper;

import ca.odell.glazedlists.gui.TableFormat;

public class ExchangeTableModel implements TableFormat<CurrencyWrapper> {

	@Override
	public int getColumnCount() {
		return TableColumnEnum.values().length;
	}

	@Override
	public String getColumnName(int column) {
		return TableColumnEnum.values()[column].getColumnName();
	}

	@Override
	public Object getColumnValue(CurrencyWrapper baseObject, int column) {
		if (column == TableColumnEnum.DATE.getColumnIndex()) {
			SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	        String date = DATE_FORMAT.format(baseObject.getDate());
			return date;
		} else if (column == TableColumnEnum.CODE.getColumnIndex()) {
			return baseObject.getCurrencyCode();
		} else if (column == TableColumnEnum.CONVERTER.getColumnIndex()) {
			return baseObject.getConverter();
		} else if (column == TableColumnEnum.AVERAGE_EXCHANGE.getColumnIndex()) {
			return baseObject.getAverageExchange();
		} else if (column == TableColumnEnum.BUY_EXCHANGE.getColumnIndex()) {
			return baseObject.getBuyExchange();
		} else if (column == TableColumnEnum.SELL_EXCHANGE.getColumnIndex()) {
			return baseObject.getSellExchange();
		}
		return "";
	}

}
